define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/hotel/hotelInfos/support",
						"AppPathDir/hotel/hotelInfos/add",
						"AppPathDir/hotel/hotelInfos/update",
						"PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/inputSelect" ],
				function(Support, AddSupport, UpdateSupport, Util, Tool, inputSelect) {
					/* 查询 start */
					$scope.cache = {
						typeArray : new Array(),
						typeMap : new Map()
					};
					$scope.search = {}
					$scope.searchSupport = {
						run : function() {
							$scope.grid.reload({
								queryParam : $scope.search
							})
						}
					};
					/* 查询 end */
					$scope.addSupport = AddSupport($scope, $compile);
					$scope.updateSupport = UpdateSupport($scope, $compile);

					$scope.delSupport = {
						run : function() {
							var selectRows = $scope.grid.getSelectedRow();
							if (null != selectRows) {
								Util.confirm("是否要删除", function() {
									var ids = new Array();
									$.each(selectRows, function(index, selectRow) {
										ids.push(selectRow.id);
									});
									$.ajax({
										url : getServer() + "/flea/hclv/hotel/deletByIds.htmls",
										method : 'post',
										data : {
											'ids' : JSON.stringify(ids)
										},
										success : function(
												data) {
											$scope.grid
													.refresh();
											Util
													.alert(data.message);
										}
									});

								});
							} else {
								Util.alert('请选择要删除的数据！');
							}
						}
					};
					$.ajax({
		                url:getServer()+"/flea/dict/initTree.htmls",
		                data:{'dictCode':'D_HOTEL_LEVEL'},
		                success:function(data){
		                    $scope.cache.typeArray = data;
		                    var data = data, len = data.length;
		                    for(var i = 0; i < len; i++){
		                    	$scope.cache.typeMap.set(data[i].dictCode, data[i].dictName);
		                    }
		                    inputSelect.dropCache();
		                    inputSelect({
		                        id:"queryLevelName",
		                        key : {
		                            id : "dictCode",
		                            name : "dictName",
		                            data : "data"
		                        },
		                        data : $scope.cache.typeArray,
		                        callback : function(id, data) {
		                        	$scope.search.queryLevel = id[0];
		                        }
		                    });
		                    $scope.grid = Support.init($scope.cache, $scope.addSupport, $scope.updateSupport, $scope.delSupport, $scope.searchSupport);
		                }
		            });
					$.ajax({
						url : getServer() + "/flea/hclv/getProvinces.htmls",
						success : function(data) {
							$scope.cache.province = data.data;
							// 初始化下拉框
							inputSelect.dropCache();
							inputSelect({
								id : "queryProvinceName",
								key : {
									id : "dictCode",
									name : "dictName",
									data : "data",
								},
								data : data.data,
								simpleData : true,
								searchAble : false,
								callback : function(id) {
									var id = id[0];
									$scope.search.queryProvince = id;
									$scope.init_city(id);
								}
							});
						}
					});
					$scope.init_city = function(id) {
						$.ajax({
							url : getServer() + "/flea/hclv/getCity.htmls",
							 data:{'pcode': id},
							success : function(data) {
								inputSelect.dropCache();
								inputSelect({
									id : "queryCityName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : data.data,
									simpleData : true,
									callback : function(id) {
										var id = id[0];
										$scope.search.queryCity = id;
										$scope.init_zone(id);
									}
								});
							}
						});
					};
					$scope.init_zone = function(id) {
						$.ajax({
							url : getServer() + "/flea/hclv/getZone.htmls",
							 data:{'pcode': id},
							success : function(data) {
								// 初始化下拉框
								inputSelect.dropCache();
								inputSelect({
									id : "queryZoneName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : data.data,
									simpleData : true,
									// 启用文本搜索
									// initData:[initProvice],
									searchAble : false,
									callback : function(id) {
										$scope.search.queryZone = id[0];
									}
								});
							}
						});
					}
				})
	}
});